
/* Author: Manfred Gschweidl */

#include "GlobusCallback.h"

namespace globus_common {

GlobusCallback::GlobusCallback() {
	globus_mutex_init(&mutex, GLOBUS_NULL);
	globus_cond_init(&cond, GLOBUS_NULL);
	done = GLOBUS_FALSE ;
}

GlobusCallback::~GlobusCallback() {
	globus_mutex_destroy(&mutex);
	globus_cond_destroy(&cond);
}

globus_bool_t GlobusCallback::isDone() {
	return done;
}

void GlobusCallback::setDone() {
	globus_mutex_lock(&mutex);
	done = GLOBUS_TRUE;
	globus_cond_broadcast(&cond);
	globus_mutex_unlock(&mutex);
}

void GlobusCallback::proceed() {
	globus_mutex_lock(&mutex);
	done = GLOBUS_FALSE;
	globus_mutex_unlock(&mutex);
}

void GlobusCallback::wait() {
	globus_mutex_lock(&mutex);
	while(!isDone()) {
		globus_cond_wait(&cond, &mutex);
	}
	globus_mutex_unlock(&mutex);
}

}


